package com.lw.common.core.service;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.lw.common.core.dao.BaseDAO;
import com.lw.common.exceptions.BizException;

/**
 * 
 * @author lw
 * 
 * @param <M>
 * @param <QM>
 */
@SuppressWarnings("all")
public abstract class BaseService<M, ID extends Serializable> implements BaseServiceI<M, ID> {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	public abstract BaseDAO<M, ID> getDao();

	public int deleteByPrimaryKey(ID id) {
		if (StringUtils.isEmpty(id))
			throw BizException.DB_ERROR_PARAM_0;
		return getDao().deleteByPrimaryKey(id);
	}

	public int insert(M record) {
		return getDao().insert(record);
	}

	public int insertSelective(M record) {
		return getDao().insertSelective(record);
	}

	public M selectByPrimaryKey(ID id) {
		if (StringUtils.isEmpty(id))
			throw BizException.DB_ERROR_PARAM_0;
		return (M) getDao().selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(M record) {
		return getDao().updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(M record) {
		return getDao().updateByPrimaryKey(record);
	}

}
